package com.zys.el.user.client;

import com.zys.el.user.po.Note;
import feign.hystrix.FallbackFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.*;

@RequestMapping(value = "/anticle")
@FeignClient(name = "search-service",fallbackFactory = AnticleClient.AnticleClientFallbackFactory.class)
public interface AnticleClient{
    @DeleteMapping("/delete/{id}")
    public ResponseEntity deleteNoteById(@PathVariable Long id);

    @PostMapping("/add")
    public ResponseEntity addNote(@RequestBody Note note);

    @Component
    @RequestMapping("/anticle-fallback-factory")
    class AnticleClientFallbackFactory implements FallbackFactory<AnticleClient> {


        Logger LOGGER = LoggerFactory.getLogger(AnticleClient.AnticleClientFallbackFactory.class);

        @Override
        public AnticleClient create(Throwable throwable) {
            throwable.printStackTrace();
            LOGGER.error(throwable.getMessage());
            return new AnticleClient() {
                @Override
                public ResponseEntity deleteNoteById(Long id) {
                    LOGGER.error("异常出现，进入fallback方法");
                    return null;
                }

                @Override
                public ResponseEntity addNote(Note note) {
                    LOGGER.error("异常出现，进入fallback方法");
                    return null;
                }
            };
        }
    }
}


